package com.lwg.datastructure.dynamicPrograming;

/**
 * @FileName: Fib.java
 * @Description: 斐波那契
 * Copyright: Copyright(C) 2020-2022
 * Company  : Sunyard.hangzhou
 * @author: 李炜光
 * @slogan:
 * @Date: 2022/2/15 0015
 */
public class Fib {

    public static void main(String[] args) {
        System.out.println(new Fib().fib(0));
    }

    public int fib(int n) {
        /*if (n < 2) {
            return n;
        }
        int dp[] = new int[n + 1];
        dp[0] = 0;
        dp[1] = 1;
        for (int i = 2; i <= n; i++) {
            dp[i] = dp[i - 1] + dp[i - 2];
        }
        return dp[n];*/

        if (n == 0) {
            return 0;
        }
        if (0 < n && n < 3) {
            return 1;
        }
        int dp[] = new int[n + 1];
        dp[0] = 0;
        dp[1] = 1;
        dp[2] = 1;
        for (int i = 3; i <= n; i++) {
            dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3];
        }
        return dp[n];
    }


}